<?php
namespace app\app\controller\v2;
use app\app\Appbase;

class GoodsCate extends Appbase 
{
	
	/**
	*获取商品分类列表
	* /app/v2/goods_cate/getList
	* 需要登录 
	* @is_need_login true
	*/
	public function getList($type=1){
		try {
			$result = model('GoodsCate')->getList( $type==2 ? 0 : request()->shopInfo['id'] );
			return $this->ReSucess($result);	
		} catch (\Exception $e) {
			return $this->ReError($e->getMessage());	
		}
	}
	
	/**
	*添加
	* /app/v2/goods_cate/add
	* 需要登录 
	* @is_need_login true
	* @method post
	*/
	public function add(){
		$request =  request();
		$param = $request ->post();
		$param['shop_id'] = $request ->shopInfo['id'];
		
		try {
			$result = model('GoodsCate')->add($param);
			if($result === false){
				return $this->ReError( model('GoodsCate')->errorInfo );
			}
			return $this->ReSucess($result);	
		} catch (\Exception $e) {
			return $this->ReError($e->getMessage());	
		}
	}
	
	/**
	* 编辑
	* /app/v2/goods_cate/edit
	* 需要登录 
	* @is_need_login true
	* @method post
	*/
	public function edit(){
		$request =  request();
		$param = $request ->post();
		$param['shop_id'] = $request ->shopInfo['id'];
		
		try {
			$result = model('GoodsCate')->edit($param);
			if($result === false){
				return $this->ReError( model('GoodsCate')->errorInfo );
			}
			return $this->ReSucess($result);	
		} catch (\Exception $e) {
			return $this->ReError($e->getMessage());	
		}
	}
	
	
	/**
	*删除店员
	* /app/v2/staff/del
	* 需要登录 
	* @is_need_login true
	*@method post 
	*/
	public function del($id){
		try {
			$result = model('GoodsCate')->del(request()->shopInfo['id'],$id);
			if(!$result){
				return $this->ReError();
			}
			return $this->ReSucess("删除成功！");	
		} catch (\Exception $e) {
			return $this->ReError($e->getMessage());	
		}
	}
	
	
}



